关于“This application has no explicit mapping for /error” | 您所在的位置:网站首页 › Unexpected Application Error › 关于“This application has no explicit mapping for /error” |
今天在开发springboot项目的时候遇到一个问题,其实不是今天遇到的,一直都存在,只不过以前没顾上解决,今天实在受不了了。 The Error Page Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Fri Apr 10 22:45:19 IST 2020 There was an unexpected error (type=Not Found, status=404). No message available实际上这个是springboot的一个全局错误页面,我的项目正常运行,但是在遇到一些诡异的异常的时候就会跳转到这个页面。 什么样的诡异问题呢,就是idea热部署以后,页面的session还在,但是session里面的内容全没了。我的项目使用shiro控制权限的,这种情况下,需要登陆的页面还是可以继续打开,并不会直接跳回登录页,但是读取session中的用户信息时候会报空指针。 当然这些不是重点,重点是这个时候就会跳转到这个Whitelabel的页面。 我在网上搜了一下,把百度结果第一页全打开了,基本上都是说Application的主类放置的路径有问题巴拉巴拉的,跟我这个情况一点不沾边。因为我访问的就是/error,而且我的controller里面明确写了 @GetMapping("/error") @ResponseBody public String globalError() { return "error"; }其实字面意思就有提示,这里用了explicit,而不是no,说明并不是没有mapping,只是mapping不是很清楚。这我就奇怪了,有经验的朋友都知道,如果我的路径里面有两个同名的mapping,springboot根本不给你启动的,直接就报错退出了! 奔着这个思路,我就看了一下启动日志,果然让我发现了一些端倪 2020-12-24 14:29:18.050 INFO 19084 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2020-12-24 14:29:18.051 INFO 19084 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)可以清楚看到,除了我自己声明的以外,还有这个BasicErrorController也有监听/error请求。现在我有点肯定,就是这个老逼给我捣的乱(不过也是奇怪,这应该不是漏洞,只是我对springboot的加载机制认识不够)。现在就是想办法怎么把它给禁用,试了几种办法,参考了这篇文章 最终给启动方法添加注解这种生效了: @SpringBootApplication @EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class}) @EnableAsync public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }再次启动,果然在启动的日志中,BasicErrorController相关的内容已经消失了,这时我再打开/error,就看到我自己写的内容了。 |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |